package cn.com.wdjedu.androidapp.wjeduandroid.support.lib.mvputils;


import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

import static cn.com.wdjedu.androidapp.wjeduandroid.support.lib.Constanct.DOMAIN;

public class HttpManager {
    public volatile  static Retrofit retrofit;
   // public static final String ENDPOINT ="http://api.xueshenx.com/";
    public static final String ENDPOINT =DOMAIN;


    public static Retrofit getInstance(){
        if (retrofit==null){
            synchronized (Retrofit.class){
                if (retrofit==null){
                    setupDaoComponent();

                }
            }
        }
        return retrofit;
    }


    //获得服务端
    public static void setupDaoComponent() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        //添加Log
        builder.addInterceptor(new LoggersInterceptor());
        //添加参数拦截器
        builder.addInterceptor(new AddQueryParameterInterceptor());
        builder.connectTimeout(NetDataConstants.CONNECTION_TIMEOUT, TimeUnit.MINUTES);
        OkHttpClient okHttpClient = builder.build();
        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(ENDPOINT)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())// 使用RxJava作为回调适配器
                .addConverterFactory(GsonConverterFactory.create())// 使用Gson作为数据转换器
                .build();
    }
}
